#include "toolswidget.h"
#include <QHBoxLayout>
#include <QPushButton>
#include <QPainter>
#include "mybutton/qiconbutton.h"
ToolsWidget::ToolsWidget(QWidget *parent)
    : QWidget{parent}
{
    m_pMainLayout = new QHBoxLayout(this);
    m_pMainLayout->setContentsMargins(0,0,0,0);
    this->setLayout(m_pMainLayout);
}

void ToolsWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    // 创建线性渐变
    QLinearGradient gradient(0, 0, width(), height());
    // 设置颜色，使用带有 alpha 通道的颜色
    gradient.setColorAt(0.0, QColor("#242027"));  // 半透明红色
    gradient.setColorAt(1.0, QColor("#45151c"));  // 半透明蓝色
    // 填充矩形

    painter.fillRect(rect(), gradient);
}

void ToolsWidget::resizeEvent(QResizeEvent *)
{
    int width = height();
    for(int i = 0; i < m_pIconBtn.size(); i++)
    {

    }

}

int ToolsWidget::addIconBtn(QString qsUrl)
{
    static int nID = 0;
    nID++;
    QSize size(height(), height());
    QIconButton* pBtn = new QIconButton(nID, qsUrl, size, this);
    pBtn->setModel(E_THREESTATUSMODEL);
    connect(pBtn, SIGNAL(sigPressed(int)), this, SLOT(slotBtnPressed(int)));
    m_pIconBtn.append(pBtn);
    m_pMainLayout->addWidget(pBtn);
    return nID;
}

void ToolsWidget::slotBtnPressed(int nID)
{
    for(int i = 0; i < m_pIconBtn.size(); i++)
    {
        if(m_pIconBtn[i]->getId() != nID
            && m_pIconBtn[i]->hasSelected())
        {
            m_pIconBtn[i]->setSelected(false);
        }
    }
}
